package com.xadmin.sys.rbac.service.impl;

import com.xadmin.sys.common.utils.Page;
import com.xadmin.sys.rbac.mapper.MenuMapper;
import com.xadmin.sys.rbac.pojo.Menu;
import com.xadmin.sys.rbac.service.MenuService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author vic Ly
 */
@Service
public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements MenuService {
    @Resource
    private MenuMapper menuMapper;

    /**
     * @param page
     * @return List<Menu>
     * @Description 分页查询
     * @Param page
     */
    @Override
    public Page<Menu> getAllByPage(Page<Menu> page) {
        List<Menu> menuList = menuMapper.getAllByPage(page);
        page.setList(menuList);
        int tatalCount = menuMapper.getCountByPage(page);
        page.setTotalCount(tatalCount);
        return page;
    }

    /**
     * 获取展开项
     * @return
     */
    @Override
    public List<Integer> findOpenIds() {
        List<Integer> ids=new ArrayList<>();
        List<Menu> menus = menuMapper.selectAll();
        if(!CollectionUtils.isEmpty(menus)){
            for (Menu menu : menus) {
                if(menu.getOpen()==1){
                    ids.add(menu.getId());
                }
            }
        }
        return ids;
    }

}
